<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="bean.DB" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改用户信息</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
        }
        .form-container {
            width: 300px;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        .form-container h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input, .form-group select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        .form-button {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
        }
        .form-button:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
<%
    String id = request.getParameter("id");
    String username = "", password = "", origin = "", gender = "", birthday = "";
    try (Connection conn = new DB().createConn();
         PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM users WHERE id = ?")) {
        pstmt.setInt(1, Integer.parseInt(id));
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            username = rs.getString("username");
            password = rs.getString("password");
            origin = rs.getString("origin");
            gender = rs.getString("gender");
            birthday = rs.getString("birthday");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
<div class="form-container">
    <h2>修改用户信息</h2>
    <form action="./alterServlet" method="post">
        <input type="hidden" name="id" value="<%= id %>">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" name="username" value="<%= username %>" required>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password">
        </div>
        <div class="form-group">
            <label for="origin">籍贯</label>
            <select id="origin" name="origin" required>
                <option value="浙江" <%= origin.equals("浙江") ? "selected" : "" %>>浙江</option>
                <option value="湖南" <%= origin.equals("湖南") ? "selected" : "" %>>湖南</option>
                <option value="香港" <%= origin.equals("香港") ? "selected" : "" %>>香港</option>
                <option value="北京" <%= origin.equals("北京") ? "selected" : "" %>>北京</option>
                <option value="上海" <%= origin.equals("上海") ? "selected" : "" %>>上海</option>
            </select>
        </div>
        <div class="form-group">
            <label for="gender">性别</label>
            <select id="gender" name="gender" required>
                <option value="男" <%= gender.equals("男") ? "selected" : "" %>>男</option>
                <option value="女" <%= gender.equals("女") ? "selected" : "" %>>女</option>
            </select>
        </div>
        <div class="form-group">
            <label for="birthday">生日</label>
            <input type="date" id="birthday" name="birthday" value="<%= birthday %>" required>
        </div>
        <button type="submit" class="form-button">保存修改</button>
    </form>
    <form action="showUser.jsp">
        <button type="submit" class="form-button">返回</button>
    </form>
</div>
</body>
</html>